package net.seehealth.healthpad.application.adapter;

import java.util.ArrayList;
import java.util.List;

import net.seehealth.healthpad.ui.view.GridItemView;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class GridViewAdapter extends BaseAdapter {
	
	/** 菜单项内容*/
	private List<String> mValues;

	/** 显示图片的资源ID*/
	private List<Integer> mImages;
	
	/** 菜单项ID */
	private List<Integer> mIds;

	/** 当前上下文 */
	private Context mContext;
	
	/** 是否显示内容下*/
	private boolean isSubContentVisiable;

	/**
	 * 构造方法
	 * @param context 当前上下文
	 * @param values 要显示的所有值
	 * @param counts 代办事宜代办数
	 * @param imgs  icon图标
	 * @param subVisiable 是否显示文字内容（下）
	 * 
	 */
	public GridViewAdapter(Context context, String[] values, int[] imgs, int[] ids, boolean subVisiable){
		mContext = context;
		mValues = new ArrayList<String>();
		mImages = new ArrayList<Integer>();
		mIds = new ArrayList<Integer>();
		isSubContentVisiable = subVisiable;
		initialize(values, imgs, ids);
	}

	/**
	 * 初始化数据
	 * @param values 所有值
	 * @param counts 待办事宜代办数
	 * @param imgs icon图标
	 */
	public void initialize(String[] values, int[] imgs, int[] ids) {
		mValues.clear();
		mImages.clear();
		mIds.clear();
		
		for(int i = 0; i < values.length; i++) {
			mValues.add(values[i]);
			mImages.add(imgs[i]);
			mIds.add(ids[i]);
		}
	}
	
	@Override
	public int getCount() {
		return mValues.size();
	}

	@Override
	public Object getItem(int position) {
		return mValues.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		if (convertView == null) {
			convertView = new GridItemView(mContext, mIds.get(position), isSubContentVisiable);
		}
		
		((GridItemView) convertView).updateView(mValues.get(position),
				mImages.get(position), mIds.get(position));
		
		return convertView;
	}

}
